<div class="container-fluid">
	<style>
		#pad-wrapper label{
			cursor: default;
			width: 30%;
		}
		.products-table .modal.fade{
			 top:-200%;
		 }
		.products-table .modal.fade.in{
			top:20%;
		}
	</style>
	<div id="pad-wrapper">
		<div class="table-wrapper products-table section">
			<div class="row-fluid head">
				<div class="span12">
					<h4>订单详情</h4>
				</div>
			</div>
			<div class="row-fluid head">
				<div class="span12">
					<label>订单号：<?php echo $orderinfo['order_no'] ?></label>
					<label>下单时间：<?php echo  date('Y-m-d G:i:s',$orderinfo['ocreate_time']) ?></label>
				</div>
			</div>
			<div class="row-fluid head">
				<div class="span12">
					<label>购买人手机号：<?php echo $orderinfo['mobile'] ?></label>
					<label>昵称：<?php echo $orderinfo['wnickname'] ?></label>
				</div>
			</div>
			<div class="row-fluid head">
				<div class="span12">
					<label>订单状态：<?php echo $orderinfo['order_status_name'] ?></label>
					<label>购买份数：<?php echo $orderinfo['product_num'] ?></label>
				</div>
			</div>
			<div class="row-fluid head">
				<div class="span12">
					<label>金额：<?php echo $orderinfo['order_amount'] ?></label>
					<label>收货人：<?php echo $orderinfo['addressee'] ?></label>
				</div>
			</div>
			<div class="row-fluid head">
				<div class="span12">
					<label>收货人手机号：<?php echo $orderinfo['telephone'] ?></label>
					<label>收货人地址：<?php echo $orderinfo['province_name']. $orderinfo['city_name']. $orderinfo['district_name']. $orderinfo['address_name'] ?></label>
				</div>
			</div>
			<div class="row-fluid head">
				<div class="span12">
					<label>付款时间：<?php if($orderinfo['opay_time'])echo  date('Y-m-d G:i:s',$orderinfo['opay_time']) ?></label>
					<label>支付方式：<?php if($orderinfo['opay_status']){ echo "微信支付";} ?></label>
				</div>
			</div>
			<div class="row-fluid head">
				<div class="span12">
					<label>支付单号：<?php echo $paylog['transaction_id'] ?></label>
					<label>发货时间：<?php if($orderinfo['osend_time'])echo  date('Y-m-d G:i:s',$orderinfo['osend_time']) ?></label>
				</div>
			</div>
			<div class="row-fluid head">
				<div class="span12">
					<label>发货快递公司：<?php if(isset($express['company_name']))echo $express['company_name'] ?></label>
					<label>发货快递单号：<?php if(isset($express['tracking_no']))echo $express['tracking_no'] ?></label>
				</div>
			</div>
			<div class="row-fluid head">
				<div class="span12">
					<label id="des">备注：<?php echo $orderinfo['order_remark'] ?></label>
				</div>
			</div>

			<div class="row-fluid">
				<table class="table table-hover">

						<?php if($orderbindd):?>
							<thead>
							<tr>
								<!-- <th class="span3"><input type="checkbox" /> 头像</th> -->
								<th class="span1"><span class="line"></span>样本号</th>
								<th class="span2"><span class="line"></span>姓名</th>
								<th class="span2"><span class="line"></span>性别</th>
								<th class="span2"><span class="line"></span>出生日期</th>
								<th class="span2"><span class="line"></span>样本回寄快递</th>
								<th class="span2"><span class="line"></span>样本状态</th>
								<th class="span1"><span class="line"></span>操作</th>
							</tr>
							</thead>
							<?php foreach ($orderbindd as $key => $value):?>
								<!-- row -->
								<tr class="first">
									<td class="order_no"><?php echo $value['order_bind_no']?></td>
									<td class="ocreate_time"><?php echo $value['info_name']?></td>
									<td class="opay_time"><?php echo $value['info_sex']?></td>
									<td class="mobile"><?php echo $value['item_report_key']?></td>
									<td class="nickname"><?php echo $value['company_company_name'].' | '.$value['express_tracking_no'] ?></td>
									<td class="product_num"><?php echo $value['order_bind_status_name']?></td>
									<td class="options">
										<?php if($value['order_bind_status'] == 3){ ?>
											<button type="button" class=" btn-flat primary" onclick="window.location.href='/sample/sampleinfo?bind_id=<?php echo $key ?>'">回寄确认</button></li>
										<?php } ?>
										<button type="button" class=" btn-flat primary" onclick="window.location.href='/sample/sampleinfo?bind_id=<?php echo $key ?>'">详细</button></li>
									</td>
								</tr>
							<?php endforeach;?>
						<?php endif;?>
				</table>
			</div>

			<div class="row-fluid head">
				<!-- 按钮触发模态框 -->
				<button class=" btn-flat primary" id="cz1" data-toggle="modal" data-target="#beizhuModel" style="background-color: #3b9ff3">
					备注/修改
				</button>

				<?php if($orderinfo['oorder_status'] == 2 ){ ?>
					<button class=" btn-flat primary" id="cz2" data-toggle="modal" data-target="#updateAdd" style="background-color: #3b9ff3">
						修改收货地址
					</button>
					<button class=" btn-flat primary" id="cz3" data-toggle="modal" data-target="#refund" style="background-color: #3b9ff3">
						退款
					</button>
					<button class=" btn-flat primary" id="cz4" data-toggle="modal" data-target="#delivery_id" style="background-color: #3b9ff3">
						发货
					</button>
				<?php }elseif($orderinfo['oorder_status'] == 3){ ?>
					<button class=" btn-flat primary" id="cz2" data-toggle="modal" data-target="#updateAdd" style="background-color: #3b9ff3">
						修改收货地址
					</button>
					<button class=" btn-flat primary" id="cz3" data-toggle="modal" data-target="#refund" style="background-color: #3b9ff3">
						退款
					</button>
				<?php }elseif($orderinfo['oorder_status'] == 5){ ?>
				<?php }elseif($orderinfo['oorder_status'] == 6){ ?>
				<?php } ?>
				<!-- 模态框（Modal） -->
				<div class="modal fade" id="beizhuModel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
					<div class="modal-dialog">
						<div class="modal-content">
							<div class="modal-body">
								备注:<input type="text" id="<?php echo $orderinfo['order_id'] ?>_bind_id" value="<?php echo $orderinfo['order_remark'] ?>" />
							</div>
							<div class="modal-footer">
								<button type="button" class="btn btn-default" data-dismiss="modal">关闭
								</button>
								<button type="button" class="btn btn-primary" id=""  data-dismiss="modal" onclick="copyText('<?php echo $orderinfo['order_id'] ?>')">
									提交更改
								</button>
							</div>
						</div><!-- /.modal-content -->
					</div><!-- /.modal -->
				</div>
				<?php if($orderinfo['oorder_status'] == 2 || $orderinfo['oorder_status'] == 3 ){ ?>
				<div class="modal fade" id="updateAdd" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="z-index:1041">
					<div class="modal-dialog">
						<div class="modal-content">
							<div class="modal-body">
								收货人姓名:<input  type="text" name="addressee" id="addressee" value="" />
							</div>
							<div class="modal-body">
								收货人手机号:<input  type="text" name="telephone" id="telephone" value="" />
							</div>
							<div class="modal-body">
								<section class="flex-wrapper flex-pack-justify">
									<select id="province" name="province" data-message="请完善地址信息！">
										<option>省</option>
										<?php foreach ($province as $item):?>
											<option value="<?php echo $item['id']?>"><?php echo $item['province_name']?></option>
										<?php endforeach;?>
									</select>
									<select id="city" name="city" data-message="请完善地址信息！">
										<option>市</option>
									</select>
									<select id="district" name="district" data-message="请完善地址信息！">
										<option>区</option>
									</select>
								</section>
							</div>
							<div class="modal-body">
								<input  type="text" name="address" id="address" value="" />
							</div>
							<div class="modal-footer">
								<button type="button" class="btn btn-default" data-dismiss="modal">关闭
								</button>
								<button type="button" class="btn btn-primary" id=""  data-dismiss="modal" onclick="addAdderr('<?php echo $orderinfo['order_id'] ?>')">
									提交更改
								</button>
							</div>
						</div><!-- /.modal-content -->
					</div><!-- /.modal -->
				</div>

				<div class="modal fade" id="refund" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
					<div class="modal-dialog">
						<div class="modal-content">
							<div class="modal-body">
								是否退款
							</div>
							<div class="modal-footer">
								<button type="button" class="btn btn-default" data-dismiss="modal">取消
								</button>
								<button type="button" class="btn btn-primary" id=""  data-dismiss="modal" onclick="orderrefund('<?php echo $orderinfo['order_id'] ?>')">
									确认
								</button>
							</div>
						</div><!-- /.modal-content -->
					</div><!-- /.modal -->
				</div>
				<?php if($orderinfo['oorder_status'] == 2 ){ ?>
					<div class="modal fade" id="delivery_id" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
						<div class="modal-dialog">
							<div class="modal-content">
								<div class="modal-body">
									发货快递公司:<section class="flex-wrapper flex-pack-justify">
										<select id="company" name="company" data-message="快递公司">
											<?php foreach ($company as $item):?>
												<option value="<?php echo $item['company_id']?>"><?php echo $item['company_name']?></option>
											<?php endforeach;?>
										</select>
									</section>
								</div>
								<div class="modal-body">
									发货快递单号:<input  type="text" name="tracking_no" id="tracking_no" value="" />
								</div>
								<?php $size=$orderinfo['product_num']; while($size--){ ?>
									<div class="modal-body">
										样本编号<?php echo $orderinfo['product_num']-$size?>:<input  type="text" name="bind_no_<?php echo $orderinfo['product_num']-$size?>" id="bind_no_<?php echo $orderinfo['product_num']-$size?>" value="" />
									</div>
									样本<?php echo $orderinfo['product_num']-$size?>回寄快递公司:<section class="flex-wrapper flex-pack-justify">
										<select id="company_<?php echo $orderinfo['product_num']-$size?>" name="company_<?php echo $orderinfo['product_num']-$size?>" data-message="快递公司">
											<?php foreach ($company as $item):?>
												<option value="<?php echo $item['company_id']?>"><?php echo $item['company_name']?></option>
											<?php endforeach;?>
										</select>
									</section>
									<div class="modal-body">
										样本<?php echo $orderinfo['product_num']-$size?>回寄快递单号:<input  type="text" name="tracking_no_<?php echo $orderinfo['product_num']-$size?>" id="tracking_no_<?php echo $orderinfo['product_num']-$size?>" value="" />
									</div>
								<?php } ?>
								<div class="modal-footer">
									<button type="button" class="btn btn-default" data-dismiss="modal">取消
									</button>
									<button type="button" class="btn btn-primary" id=""  data-dismiss="modal" onclick="delivery('<?php echo $orderinfo['order_id'] ?>')">
										确认
									</button>
								</div>
							</div><!-- /.modal-content -->
						</div><!-- /.modal -->
					</div>
				<?php } ?>
				<?php } ?>
			</div>
		</div>
		<!-- end products table -->

	</div>
	<style>
		h4{
			padding-bottom:25px;
		}
		label{
			display:inline-block;
			margin-right:10px;
			margin-left:20px;
			vertical-align:middle;
		}
		.disabled,.disabled:hover{
			background-color:#e6e6e6 !important;
			border:1px solid #e6e6e6 !important;
			color:gray;
		}
	</style>
	<script type="text/javascript" src="/js/jquery-1.7.2.min.js"></script>
	<script type="text/javascript">
		function addAdderr(order_id){
			var $addressee =$("#addressee").val();
			var $telephone =$("#telephone").val();
			var $province_id =$("#province").val();
			var $city_id =$("#city").val();
			var $district_id =$("#district").val();
			var $address =$("#address").val();
			var $user_id =<?php echo $orderinfo['user_id'] ?>;
			var $order_id =<?php echo $orderinfo['order_id'] ?>;
			var $url = '/address/save';
			$.ajax({
				type: 'post',
				url: $url,
				cache: false,
				data:{addressee:$addressee,telephone:$telephone,province_id:$province_id,city_id:$city_id,district_id:$district_id,address:$address,user_id:$user_id,order_id:$order_id},
				dataType: 'json',
				success: function (data) {
					if(data.error == 1)
					{
						alert(data.msg);
					}else {
						alert(data.msg);
						window.location.href='/shop-order/orderinfo?id=<?php echo $orderinfo['order_id'] ?>';
					}
				},

				error: function () {
					alert("系统繁忙，请联系客服！400-821-0418");
				}
			});
		}

		//改变记录页面显示
		function change(data)
		{
		$('#des').html("备注："+data)//显
		$('#<?php echo $orderinfo['order_id'] ?>_bind_id').val(data)//显
		}

		//提交地址
		function copyText(order_id){
			var $des =$("#"+order_id+"_bind_id").val();
			var $url = '/shop-order/ajaxdes';
			$.ajax({
				type: 'post',
				url: $url,
				cache: false,
				data:{des:$des,order_id:order_id},
				dataType: 'json',
				success: function (data) {
					if(data.error == 1)
					{
						alert(data.msg);
					}else {
						//修改页面内容
						change(data.data);
					}
				},

				error: function () {
					alert("系统繁忙，请联系客服！400-821-0418");
				}
			});
		}

		//提交地址
		function orderrefund(order_id){
			var $url = '/shop-order/ajaxrefund';
			$.ajax({
				type: 'post',
				url: $url,
				cache: false,
				data:{order_id:order_id},
				dataType: 'json',
				success: function (data) {
					if(data.error == 1)
					{
						alert(data.msg);
					}else {
						//修改页面内容
						alert(data.msg);
						window.location.href='/shop-order/orderinfo?id=<?php echo $orderinfo['order_id'] ?>';
					}
				},

				error: function () {
					alert("系统繁忙，请联系客服！400-821-0418");
				}
			});
		}

		function delivery(order_id)
		{
			var $url = '/shop-order/ajaxdelivery';
			//获取数据发送快递单号
			var companyarr=new Array();
			var tracking_noarr=new Array();
			var bind_noarr=new Array();
			company =$("#company").val();
			tracking_no =$("#tracking_no").val();

			//获取
			var $size=<?php echo $orderinfo['product_num'] ?>;
			var $product_num=<?php echo $orderinfo['product_num'] ?>;

			while($product_num--) {
				companyarr[$size - $product_num - 1] = $("#company_" + ($size - $product_num)).val();
				tracking_noarr[$size - $product_num - 1] = $("#tracking_no_" + ($size - $product_num)).val();
				bind_noarr[$size - $product_num - 1] = $("#bind_no_" + ($size - $product_num)).val();
			}
			$.ajax({
				type: 'post',
				url: $url,
				cache: false,
				data:{order_id:order_id,company:company,tracking_no:tracking_no,companyarr:JSON.stringify(companyarr),tracking_noarr:JSON.stringify(tracking_noarr),bind_noarr:JSON.stringify(bind_noarr)},
				dataType: 'json',
				success: function (data) {
					if(data.error == 1)
					{
						alert(data.msg);
					}else {
						//修改页面内容
						alert(data.msg);
						window.location.href='/shop-order/orderinfo?id=<?php echo $orderinfo['order_id'] ?>';
					}
				},

				error: function () {
					alert("系统繁忙，请联系客服！400-821-0418");
				}
			});
		}

	</script>

	<script type="text/javascript">
		$(function () {
			$(".isDefault").click(function (e) {
				if (!$(this).hasClass("active")) {
					$(this).addClass("active");
					$("#is_default").val("1");
				} else {
					$(this).removeClass("active");
					$("#is_default").val("0");
				}
			});

			$("#province").live('change', function (e) {
				var val = $(this).val();
				$.post('/address/ajaxcitysbyprovincesid', {
					'value': val
				}, function (res) {
					var list_length = res.data.length;
					var city_html = '<option value="">市</option>';
					if (list_length > 0) {
						for (var i = 0; i < list_length; i++) {
							var data = res.data[i];
							city_html += '<option value=' + data.id + '>' + data.city_name + '</option>';
						}
					}
					$('#city').html(city_html);
					var html1 = '<option value="">区</option>';
					$('#district').html(html1);
					$("#province option").removeAttr("selected");
					$("#province").find("option[value='" + val + "']").attr("selected", "selected");
				}, 'json');
			});

			$("#city").live('change', function (e) {
				var val = $(this).val();
				$.post('/address/ajaxareasbycityid', {
					'value': val
				}, function (res) {
					var list_length = res.data.length;
					var html = '<option value="">区</option>';
					if (list_length > 0) {
						for (var i = 0; i < list_length; i++) {
							var data = res.data[i];
							html += '<option value=' + data.id + '>' + data.district_name + '</option>';
						}
					}
					$('#district').html(html);
					$("#city option").removeAttr("selected");
					$("#city").find("option[value='" + val + "']").attr("selected", "selected");
				}, 'json');
			});

			$("#district").live('change', function (e) {
				var val = $(this).val();
				$("#district option").removeAttr("selected");
				$("#district").find("option[value='" + val + "']").attr("selected", "selected");
			});
		});
	</script>
</div>


